home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / os2life / mouapi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-29  |  3.9 KB  |  138 lines

  1. /***    mouapi.c - A library of real mode mouse calls compatable with OS/2
  2.  *
  3.  *    A subset of the OS/2 mouse api calls for real mode calls.
  4.  *    The calls and features are designed specifically for LIFE.C.
  5.  *    This is designed as a library to be linked with an application
  6.  *    using BIND.EXE to allow full compatability between real and
  7.  *    protect modes for programs using mouse calls.
  8.  *    Most are merely dummy calls because DOS 3.x doesn't care about
  9.  *    such things.
  10.  *
  11.  *    Contains subsets of:
  12.  *        MouOpen, MouReadEventQue, MouSetDevStatus,
  13.  *        MouGetNumQueEl, MouSetPtrPos
  14.  *
  15.  *  Created by Microsoft Corp. 1987
  16.  */
  17. #define INCL_SUB
  18.  
  19. #include <os2def.h>
  20. #include <bsesub.h>
  21.  
  22. /* defines for int33h() calls.    These are the offsets for the various registers
  23.  *     in the register array. */
  24. #define AX 0
  25. #define BX 1
  26. #define CX 2
  27. #define DX 3
  28.  
  29.  
  30. /***    MouOpen - initializes mouse
  31.  *
  32.  *    Initializes mouse and returns -1 in handle if mouse is present, else
  33.  *    if no mouse is present, returns 0 in handle and error code.
  34.  */
  35. unsigned APIENTRY
  36. MouOpen (name, handle)
  37. PSZ name;
  38. PHMOU handle;
  39. {
  40.     extern void int33h();            /* mouse interupt caller */
  41.     int registers[4];            /* register array for above */
  42.  
  43.     registers[AX]=0;            /* ax=0, mouse init */
  44.     int33h (registers);            /* do mouse call */
  45.     if (registers[AX] == -1) {        /* was mouse present? */
  46.         *handle=-1;            /* if yes, give dummy handle */
  47.         registers[AX]=15;        /* set mickey to pixel */
  48.         registers[CX]=8;        /*    ratio to 1:1 */
  49.         registers[DX]=8;
  50.         int33h(registers);
  51.         return (0);            /* and return no error */
  52.     }
  53.     else {
  54.         *handle=0;
  55.         return (385);            /* else, return no mouse err */
  56.     }
  57. }
  58.  
  59.  
  60. /***    MouReadEventQue - get mouse event
  61.  *
  62.  *    Gets events like the OS/2 MouReadEventQue but this one ignores
  63.  *    the event mask and EventType parameter, never waiting for events,
  64.  *    just returning a 0 mask if nothing happened since last call.
  65.  *    Returns position absolute pixel coordinates
  66.  */
  67. unsigned APIENTRY
  68. MouReadEventQue (buffer, type, handle)
  69.     PMOUEVENTINFO buffer;
  70.     PUSHORT type;
  71.     HMOU handle;
  72. {
  73.     extern void int33h();            /* mouse interupt caller */
  74.     int registers[4];            /* register array for above */
  75.     static lastrow;             /* position at last call */
  76.     static lastcol;
  77.  
  78.     buffer->Time=-1L;            /* put in dummy time figure */
  79.     registers[AX]=3;            /* ax=3, get mouse status */
  80.     int33h (registers);            /* do mouse call */
  81.     buffer->fs=0;                /* first, blank button info */
  82.     if (registers[DX]-lastrow || registers[CX]-lastcol) {
  83.         buffer->row=registers[DX];    /* return row */
  84.         buffer->col=registers[CX];    /* return column */
  85.         lastrow=registers[DX];        /* save for next time */
  86.         lastcol=registers[CX];
  87.         if (registers[BX] & 1)        /* if the left button is down*/
  88.             (buffer->fs) |= 2;    /*   then set appropriate bit*/
  89.         if (registers[BX] & 2)        /* if the right button down*/
  90.             (buffer->fs) |= 8;    /*   then set appropriate bit*/
  91.         else if (!(registers[BX] & 1))    /* if no buttons, but motion */
  92.             buffer->fs |= 1;    /*   then set apporpriate bit*/
  93.     }
  94.     if (registers[BX] & 1)        /* if the left button is down*/
  95.         (buffer->fs) |= 4;    /*   then set appropriate bit*/
  96.     if (registers[BX] & 2)        /* if the right button down*/
  97.         (buffer->fs) |= 16;    /*   then set appropriate bit*/
  98.     return (0);                /* return no error */
  99. }
  100.  
  101.  
  102. /*** MouSetDevStatus - Dummy function, included for maximum compatibility
  103.  */
  104. unsigned APIENTRY
  105. MouSetDevStatus (status, handle)
  106. PUSHORT status;
  107. HMOU handle;
  108. {
  109. }
  110.  
  111.  
  112. /*** MouGetNumQueEl - Always returns 1 in .Events
  113. */
  114. unsigned APIENTRY
  115. MouGetNumQueEl (info, handle)
  116. PMOUQUEINFO info;
  117. HMOU handle;
  118. {
  119.     info->cEvents = 1;
  120. }
  121.  
  122.  
  123. /*** MouSetPtrPos - Sets mouse pointer position
  124. */
  125. unsigned APIENTRY
  126. MouSetPtrPos (loc, handle)
  127. PPTRLOC loc;
  128. HMOU handle;
  129. {
  130.     int registers[4];            /* for int33h() */
  131.  
  132.     registers[AX]=4;            /* int 33 set position funct */
  133.     registers[CX]=loc->col;         /* new coordinates */
  134.     registers[DX]=loc->row;
  135.     int33h (registers);            /* do it */
  136. }
  137. 
  138.